﻿using System.Xml.Linq;

namespace _38_C_中匿名类型
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "C#中匿名类型";

            //var anon = new { name = "张三", age = 1 };

            //Console.WriteLine($"{anon.name}  age{anon.age}");
            //Console.WriteLine(anon.ToString());

            //var anon1 = anon with { name = "李四", age = 1 };//with 可以修改 
            //Console.WriteLine($"{anon1.name}  age{anon1.age}");

            //List<Person> persons = new List<Person>()
            //{
            //    new Person (){ Id=1,Name="张三",age=20},
            //    new Person (){ Id=1,Name="李四",age=21}
            //};
            //var tempList = from person in persons select new { person.Name  ,person.age };

            //foreach (var item in tempList)
            //{
            //    Console.WriteLine($"{item.Name}  {item.age}");
            //}

            //var anon1 = new { name = "张三", age = 1 };
            //var anon2 = new { name = "张三", age = 1 };

            //Console.WriteLine(anon1.Equals(anon2));//true 顺序和位置要一致

            //匿名数组
            var tempArray = new[] { new { name = "张三", age = 1 }, new { name = "李四", age = 12 } };



            Console.ReadKey();
        }
    }
}
